﻿#include <iostream>
#include <map>
using namespace std;
//map容器大小和交换
void Printmap(map<int, int>& mp)
{
	for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		cout << "key的值为：" << it->first << endl;
		cout << "value的值为：" << it->second << endl;
	}
	cout << endl;
}
void test01()
{
	map<int, int>mp;
	mp.insert(pair<int, int>(1, 10));
	mp.insert(pair<int, int>(2, 20));
	mp.insert(pair<int, int>(3, 30));
	mp.insert(pair<int, int>(4, 40));
	if (mp.empty())
	{
		cout << "map容器为空" << endl;
	}
	else
	{
		cout << "map容器不为空" << endl;
		cout << "map容器的大小为：" << endl;
		cout << mp.size();
	}
}
//交换
void test02()
{
	map<int, int>mp;
	mp.insert(pair<int, int>(1, 10));
	mp.insert(pair<int, int>(2, 20));
	mp.insert(pair<int, int>(3, 30));
	mp.insert(pair<int, int>(4, 40));
	map<int, int>mp2;
	mp2.insert(pair<int, int>(5, 100));
	mp2.insert(pair<int, int>(6, 200));
	mp2.insert(pair<int, int>(7, 300));
	mp2.insert(pair<int, int>(8, 400));
	cout << "交换前:" << endl;
	Printmap(mp);
	Printmap(mp2);
	cout << "交换后:" << endl;
	cout << endl;
	mp.swap(mp2);
	Printmap(mp);
	Printmap(mp2);
}
int main()
{
	test01();
	test02();
}